package Reflex;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Reflex {
    public static void main(String[] args) throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Persion p = new Persion(20);
        Reflex.test(p);
    }

    static void test(Object obj) throws NoSuchFieldException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
        Class<? extends Object> c = obj.getClass();

        Field AgeField = c.getDeclaredField("age");
        AgeField.setAccessible(true);
        System.out.println(AgeField);
        System.out.println(AgeField.getType());
        System.out.println(AgeField.getInt(obj));

        Method GetAgeMethod = c.getDeclaredMethod("getAge");
        GetAgeMethod.setAccessible(true);
        System.out.println(GetAgeMethod);
        System.out.println(GetAgeMethod.getReturnType());
        System.out.println(GetAgeMethod.invoke(obj));

        System.out.println(c.getDeclaredAnnotation(MyAnno.class).name());
        System.out.println(AgeField.getDeclaredAnnotation(MyAnno.class).name());
    }
}


@MyAnno
class Persion{
    @MyAnno(name = "cc")
    private int age = 10;

   Persion(int age){
       this.age = age;
   }

    int getAge(){
        return age;
    }
}